//
//  YBMineUseRecordVC.swift
//  Moonlight
//
//  Created by Penlon Kim on 2023/7/1.
//  Copyright © 2023 Moonlight Game Streaming Project. All rights reserved.
//

import UIKit
import SnapKit
import SwiftyJSON
import HandyJSON
import JXPagingView

class YBMineUseRecordVC: BaseVC {
    
    // MARK: Lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigation.item.title = "使用记录"
        
        let zLabel = self.bk_addLabel(text: "至", font: .systemFont(ofSize: 12), bgColor: .clear, textColor: .lightBlack51DarkLight230, align: .center)
        
        view.backgroundColor = .lightGray248Dark17
        view.addSubviews([tableView, startTimeBtn, endTimeBtn, zLabel])
        
        startTimeBtn.snp.makeConstraints { make in
            make.size.equalTo(CGSizeMake(110, 25))
            make.top.equalTo(kNavigationBarHeight+12)
            make.left.equalTo(12)
        }
        
        zLabel.snp.makeConstraints { make in
            make.centerY.equalTo(startTimeBtn)
            make.left.equalTo(startTimeBtn.snp.right).offset(12)
        }
        
        endTimeBtn.snp.makeConstraints { make in
            make.size.equalTo(CGSizeMake(110, 25))
            make.centerY.equalTo(startTimeBtn)
            make.left.equalTo(zLabel.snp.right).offset(12)
        }
        
        tableView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(startTimeBtn.snp.bottom).offset(12)
        }
        
    }
    
    // MARK: - lazy
    lazy var vm: YBMineViewModel = {
        let vm = YBMineViewModel()
        return vm
    }()
    
    private lazy var tableView: UITableView = {
        let tv = UITableView(frame: .zero, style: .grouped)
        tv.backgroundColor = .lightGray242Dark17
        tv.estimatedRowHeight = 44
        tv.rowHeight = UITableView.automaticDimension
        tv.separatorStyle = .none
        tv.showsVerticalScrollIndicator = false
        tv.tableFooterView = UIView()
        tv.delegate = self
        tv.dataSource = self
        if #available(iOS 15.0, *) {
            tv.sectionHeaderTopPadding = 0
        }
        tv.register(cellWithClass: YBMineUseRecordCell.self)
        return tv
    }()
    
    private lazy var startTimeBtn: BKLayoutButton = {
        let btn = self.bk_addLayoutButton(style: .leftTitleRightImage, bgColor: .lightWhiteDark27, imageSize: CGSizeMake(12, 12), image: UIImage(named: "icon_mine_down"), titleFont: .systemFont(ofSize: 12), title: "2023-05-23", titleColor: .lightBlack51DarkLight230)
        btn.bk_addCornerBorder(radius: 25/2, borderWidth: 1.0, borderColor: ColorDef.gray153)
        btn.bk_addTarget { sender in
            
        }
        return btn
    }()
    
    private lazy var endTimeBtn: BKLayoutButton = {
        let btn = self.bk_addLayoutButton(style: .leftTitleRightImage, bgColor: .lightWhiteDark27, imageSize: CGSizeMake(12, 12), image: UIImage(named: "icon_mine_down"), titleFont: .systemFont(ofSize: 12), title: "2023-05-23", titleColor: .lightBlack51DarkLight230)
        btn.bk_addCornerBorder(radius: 25/2, borderWidth: 1.0, borderColor: ColorDef.gray153)
        btn.bk_addTarget { sender in
            
        }
        return btn
    }()
    
}

// MARK: - UITableView代理
extension YBMineUseRecordVC: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return UIView()
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0.01
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return UIView()
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 10
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withClass: YBMineUseRecordCell.self, for: indexPath)
        cell.updateCell()
        return cell
        
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }
    
}
